package org.knot.autojmx.metadata;

import java.lang.reflect.Method;

import javax.management.MBeanParameterInfo;

/**
 * 
 * @author <a href="mailto:yuxiaoweimail@gmail.com">yuxiaowei</a>
 *
 */
public class MethodField {

    private String m_description;
    
    private Method  m_method;

    public MethodField(Method method, String description) {
        this.m_method = method;
        this.m_description = description;

    }

    public Method getMethod() {
        return m_method;
    }

    public String getDescription() {
        return m_description;
    }

    public String getName() {
        return m_method.getName();
    }

    /**
     * Gets the parameter in JMX format.
     * 
     * @return info on JMX format
     */
    public MBeanParameterInfo[] getParams() {
        MBeanParameterInfo[] mbean = new MBeanParameterInfo[m_method.getParameterTypes().length];
        for (int i = 0; i < m_method.getParameterTypes().length; i++) {
            mbean[i] = new MBeanParameterInfo("arg" + i, m_method
                .getParameterTypes()[i].getName(), null);
        }
        return mbean;
    }


    public String getReturnType() {
        return m_method.getReturnType().getName();
    }

}
